﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using ResearchRepository.Models;

namespace eoTest
{
	public partial class RRBrowse : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			try
			{
				RRFile rootFile = RRDatabaseManager.getFileData(RRFile.EmptyRoot, Session[GLOBALS.userObjSessionVar] == null ? RRUser.GuestUserID : ((RRUser) Session[GLOBALS.userObjSessionVar]).UserID, 3);
				fileBrowserTree.Nodes.Clear();
				fileBrowserTree.Nodes.Add("/ (" + rootFile.FileID + "), (user=" + rootFile.UserPermission + " >= public=" + rootFile.PublicPermission + ")");
				populateTree(fileBrowserTree.Nodes[0], rootFile);
				//TODO populate each level on-demand + more testing
			}
			catch(Exception x)
			{
			}
		}

		protected void populateTree(EO.Web.TreeNode node, RRFile file)
		{
			if (file.IsDir)
			{
				for (int i = 0; i < file.SubFiles.Count; i++)
				{
					node.ChildNodes.Add(file.SubFiles[i].FileName + " (" + file.SubFiles[i].FileID + "), (user=" + file.SubFiles[i].UserPermission + " >= public=" + file.SubFiles[i].PublicPermission + ")");
					populateTree(node.ChildNodes[i], file.SubFiles[i]);
				}
			}
		}
	}
}